<?php
class CategoryMappingController extends Zend_Controller_Action
{
	public function init()
	{
		ini_set('memory_limit', '-1');
		IndexController::initAdmin($this);
	}
	
	public function importAction()
	{
		if($this->_request->isPost())
		{
			$objFile	= isset($_FILES['file']) ? $_FILES['file'] : null ;
			
			if(!$objFile['name'])
			{
				echo '<script>parent.show_error("categorymapping", "null")</script>';
				exit;
			}
			
			$arrKey			= array('category_id', 'level1', 'level2', 'level3', 'level4', 'level5', 'level6');
			$strQuery		= "TRUNCATE TABLE category_mapping; 
							LOAD DATA LOCAL INFILE '".str_replace('\\', '/', $objFile['tmp_name'])."' 
							INTO TABLE category_mapping 
							FIELDS TERMINATED BY ',' ENCLOSED BY '\"'
							LINES TERMINATED BY '\r\n'
							IGNORE 1 LINES (".implode(',', $arrKey).")";
			
			$db		= Zend_Registry::get('db');
			$db->execute($strQuery);
			
			$db->closeConnection();
			echo '<script>parent.update_done();</script>' . $objFile;
			exit;
		}
	}
}
?>
